package com.zxy.supplier_system.server.repository

import com.zxy.supplier_system.server.entity.AdministrativeRegion
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query

interface AdministrativeRegionRepository : JpaRepository<AdministrativeRegion, String> {

    // 一次性获取所有省市区数据
    @Query("SELECT new com.zxy.supplier_system.server.repository.RegionProjection( r.code, r.name, r.parent.code) AS parentCode FROM AdministrativeRegion r")
    fun findAllRegionProjections(): List<RegionProjection>


    

}

// 投影接口用于优化查询
data class RegionProjection (
    val code:String,
    val name:String,
    val parentCode:String?,
)